package com.example.administrator.dagger2demo.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.example.administrator.dagger2demo.R;

import in.srain.cube.views.ptr.PtrDefaultHandler2;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.header.StoreHouseHeader;
import in.srain.cube.views.ptr.util.PtrLocalDisplay;

/**
 * Created by Administrator on 2016/5/21.
 */
public class TestUi extends AppCompatActivity {
    PtrFrameLayout mPtrFrameLayout;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_ui);
        mPtrFrameLayout = (PtrFrameLayout)  findViewById(R.id.material_style_ptr_frame);



        //添加头部
        StoreHouseHeader header = new StoreHouseHeader(this);
        header.setPadding(0, PtrLocalDisplay.dp2px(20), 0, PtrLocalDisplay.dp2px(20));
        header.initWithString("Ultra PTR");
        header.setBackgroundColor(getResources().getColor(R.color.colorAccent));

        mPtrFrameLayout.setDurationToCloseHeader(1500);
        mPtrFrameLayout.setHeaderView(header);
        mPtrFrameLayout.addPtrUIHandler(header);



        //添加底部
        StoreHouseHeader footer = new StoreHouseHeader(this);
        footer.setPadding(0, PtrLocalDisplay.dp2px(20), 0, PtrLocalDisplay.dp2px(20));
        footer.initWithString("Ultra Footer");
        footer.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        mPtrFrameLayout.setFooterView(footer);
        mPtrFrameLayout.addPtrUIHandler(footer);





        mPtrFrameLayout.setPtrHandler(new PtrDefaultHandler2() {
            @Override
            public void onLoadMoreBegin(PtrFrameLayout ptrFrameLayout) {
                mPtrFrameLayout.refreshComplete();
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
                mPtrFrameLayout.refreshComplete();
            }
        });
    }
}
